package com.ifgi.sitcom.campusmapperNDrawer.controllers;

import java.util.ArrayList;

import android.util.Log;

import com.gamificationlibrary.model.leaderboard.Leaderboard;
import com.gamificationlibrary.model.*;
import com.ifgi.sitcom.campusmapperNDrawer.indoordata.FloorPlan;
import com.ifgi.sitcom.campusmapperNDrawer.io.*;
import com.ifgi.sitcom.campusmapperNDrawer.outdoordata.Building;



public class OwnershipController {
	
	private static OwnershipController instance=null;

    public static OwnershipController getInstance() {
       if(instance==null)
    	instance=new OwnershipController();
	return instance;
    }

   	
	public ArrayList<Ownership<Building>> setAllOwnersBuildings()
	{
		ArrayList<Ownership<Building>> allOwners=new ArrayList<Ownership<Building>>();
		RDFReader read=new RDFReader();
		ArrayList<Ownership<Building>> owners = read.getOwnersBuildings2();
		TripleStoreQueries triples=new TripleStoreQueries();
		//String nearby=" ?building omgeo:nearby (51.9628942 7.625496 '0.5km') .";
		ArrayList<Building> allBuildings=triples.queryBuildingsModified("");
		
		int j=0;
		
		for(int i=0;i<allBuildings.size();i++)
		{
			Ownership<Building> owner;
			
			if(j<owners.size())
			{
				
			if(allBuildings.get(i).getBuildingURI().equals(owners.get(j).getT().getBuildingURI()))
			{
				owner=owners.get(j);
				j++;
			}
			else
			{
				owner=new Ownership<Building>();
				owner.setT(allBuildings.get(i));
			}
			}
			else
			{
				owner=new Ownership<Building>();
				owner.setT(allBuildings.get(i));
			}
			allOwners.add(owner);
		}
	
		return allOwners;
	}
	

	public ArrayList<Ownership<FloorPlan>> getFloorOwnerships(String buildingName) {
		// TODO Auto-generated method stub
		RDFReader read=new RDFReader();
		return read.getOwnersFloors(buildingName);
	}
	
}
